home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
print
/
gsview10.zip
/
init.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
18KB
|
515 lines
/*
* init.c -- Initialisation functions for GSVIEW.EXE,
* a graphical interface for MS-Windows Ghostscript
* Copyright (C) 1993 Russell Lang
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Russell Lang
* Internet: rjl@monu1.cc.monash.edu.au
*/
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <commdlg.h>
#include <shellapi.h>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dir.h>
#include <io.h>
#define NeedFunctionPrototypes 1
#include "ps.h"
#include "gsview.h"
/* Open/Save File Dialog Box */
OPENFILENAME ofn;
char szOFilename[MAXSTR]; /* filename for OFN */
char szOFilter[256]; /* filter for OFN */
/* buttons */
WNDPROC lpfnButtonWndProc; /* default button WndProc */
struct buttonlist {
HWND hbutton;
struct buttonlist *next;
};
struct buttonlist *buttonhead, *buttontail;
int real_button_width;
/* Don't start another instance - use previous instance */
void
gsview_init0(LPSTR lpszCmdLine)
{
HWND hwnd = FindWindow(szClassName, szAppName);
BringWindowToTop(hwnd);
if (lstrlen(lpszCmdLine) != 0) {
/* open file specified on command line */
LPSTR szFile = GlobalAllocPtr(GHND | GMEM_SHARE, lstrlen(lpszCmdLine)+1);
if (szFile) {
lstrcpy(szFile, lpszCmdLine);
PostMessage(hwnd, WM_COMMAND, IDM_DROP, (LPARAM)szFile);
}
}
}
/* main initialisation */
void
gsview_init1(LPSTR lpszCmdLine)
{
WNDCLASS wndclass;
WORD version = LOWORD(GetVersion());
char *p;
char workdir[MAXSTR];
char filedir[MAXSTR];
int length = 64;
while (length && !SetMessageQueue(length))
length--; /* reduce size and try again */
if (length == 0)
exit(0); /* panic */
if ((LOBYTE(version)<<8) + HIBYTE(version) >= 0x30a)
is_win31 = TRUE;
/* get path to help file */
GetModuleFileName(phInstance, szHelpName, sizeof(szHelpName));
if ((p = strrchr(szHelpName,'\\')) != (char *)NULL)
p++;
else
p = szHelpName;
LoadString(phInstance, IDS_HELPFILE, p, sizeof(szHelpName) - (p-szHelpName));
/* help message for GetOpenFileName Dialog Box */
help_message = RegisterWindowMessage(HELPMSGSTRING);
LoadString(phInstance, IDS_TOPICROOT, szHelpTopic, sizeof(szHelpTopic));
/* register the window class */
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndImgProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(LONG);
wndclass.hInstance = phInstance;
wndclass.hIcon = LoadIcon(phInstance,"gsview");
wndclass.hCursor = LoadCursor((HINSTANCE)NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szClassName;
RegisterClass(&wndclass);
/* defaults if entry not in gsview.ini */
strcpy(szGSwin, DEFAULT_GSCOMMAND);
img_origin.x = img_origin.y = CW_USEDEFAULT;
img_size.x = img_size.y = CW_USEDEFAULT;
xdpi = ydpi = DEFAULT_RESOLUTION;
button_show = TRUE;
epsf_clip = FALSE;
epsf_warn = FALSE;
media = IDM_LETTER;
quick = TRUE;
redisplay = FALSE;
safer = TRUE;
save_dir = TRUE;
settings = TRUE;
timeout = DEFAULT_TIMEOUT;
orientation = IDM_PORTRAIT;
swap_landscape = FALSE;
hmenu = LoadMenu(phInstance, "gsview_menu");
GetMenuString(hmenu, media, medianame, sizeof(medianame), MF_BYCOMMAND);
haccel = LoadAccelerators(phInstance, "gsview_accel");
getcwd(workdir, sizeof(workdir));
/* read entries from gsview.ini */
read_profile();
hwndimg = CreateWindow(szClassName, (LPSTR)szAppName,
WS_OVERLAPPEDWINDOW,
img_origin.x, img_origin.y,
img_size.x, img_size.y,
NULL, NULL, phInstance, (void FAR *)NULL);
/* load DLL for sounds */
if (is_win31) {
/* MMSYSTEM.DLL requires Windows 3.1, so to allow gsview to run
under Windows 3.0 we can't use the import library */
hlib_mmsystem = LoadLibrary("MMSYSTEM.DLL");
if (hlib_mmsystem >= HINSTANCE_ERROR) {
lpfnSndPlaySound = (FPSPS)GetProcAddress(hlib_mmsystem, "sndPlaySound");
}
else {
gserror(IDS_SOUNDNOMM, NULL, MB_ICONEXCLAMATION, -1);
hlib_mmsystem = (HINSTANCE)NULL;
}
}
if (lstrlen(lpszCmdLine) >= 2) {
if ( ((lpszCmdLine[0] == '/') || (lpszCmdLine[0] == '-'))
&& ((lpszCmdLine[1] == 'D') || (lpszCmdLine[1] == 'd')) ) {
debug = TRUE;
lpszCmdLine += 2;
while (*lpszCmdLine && (*lpszCmdLine == ' '))
lpszCmdLine++;
}
}
if (lstrlen(lpszCmdLine) != 0) {
/* open file specified on command line */
LPSTR szFile = GlobalAllocPtr(GHND, lstrlen(lpszCmdLine)+1);
if (szFile) {
lstrcpy(szFile, lpszCmdLine);
PostMessage(hwndimg, WM_COMMAND, IDM_DROP, (LPARAM)szFile);
}
/* ignore last saved directory */
/* use directory of file if given, or work directory */
if ((lpszCmdLine[0] == '/') || (lpszCmdLine[0] == '-')) {
lpszCmdLine += 2;
while (*lpszCmdLine && (*lpszCmdLine == ' '))
lpszCmdLine++;
}
lstrcpy(filedir, lpszCmdLine);
if ( (p = strrchr(filedir, '\\')) == (char *)NULL ) {
if ( (p = strrchr(filedir, ':')) == (char *)NULL )
strcpy(filedir, workdir); /* no path so use work directory */
else
*(++p) = '\0';
}
else
*(++p) = '\0';
if (!((strlen(filedir)==2) && isalpha(filedir[0]) && (filedir[1]==':')))
chdir(filedir);
if (isalpha(filedir[0]) && (filedir[1]==':'))
(void) setdisk(toupper(filedir[0])-'A');
}
play_sound(SOUND_START);
}
/* create gsview window menu bar and buttons */
void
gsview_create()
{
int i;
char cReplace;
WNDCLASS wndclass;
HGLOBAL hglobal;
int FAR *pButtonID;
TEXTMETRIC tm;
HDC hdc;
HWND hbutton;
WNDPROC lpfnMenuButtonProc;
POINT char_size; /* size of default text characters */
POINT button_size, button_shift;
/* setup OPENFILENAME struct */
if (!LoadString(phInstance, IDS_FILTER, szOFilter, sizeof(szOFilter)-1))
return;
cReplace = szOFilter[strlen(szOFilter)-1];
for (i=0; szOFilter[i] != '\0'; i++)
if (szOFilter[i] == cReplace)
szOFilter[i] = '\0';
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwndimg;
ofn.lpstrFilter = szOFilter;
ofn.nFilterIndex = FILTER_PS;
ofn.lpstrFile = szOFilename;
ofn.nMaxFile = sizeof(szOFilename);
ofn.lpstrFileTitle = (LPSTR)NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrTitle = (LPSTR)NULL;
ofn.lpstrInitialDir = (LPSTR)NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_SHOWHELP;
LoadString(phInstance, IDS_TOPICROOT, szHelpTopic, sizeof(szHelpTopic));
/* add menu to image window */
SetMenu(hwndimg, hmenu);
/* get default text size */
hdc = GetDC(hwndimg);
GetTextMetrics(hdc,(LPTEXTMETRIC)&tm);
ReleaseDC(hwndimg,hdc);
char_size.x = tm.tmAveCharWidth;
char_size.y = tm.tmHeight;
/* set size of info area, buttons and offset to child window */
info_rect.left = 0;
info_rect.right = info_rect.left + 60 * char_size.x;
info_rect.top = 0;
info_rect.bottom = char_size.y;
button_size.x = 24;
button_size.y = 24;
button_shift.x = 0;
button_shift.y = button_size.y - 1;
button_rect.top = info_rect.bottom;
button_rect.left = -1;
button_rect.right = button_size.x - 2;
button_rect.bottom = 0; /* don't care */
real_button_width = button_rect.right;
if (!button_show)
button_rect.right = 0;
img_offset.x = button_rect.right + (button_show ? 1 : 0);
img_offset.y = info_re